package org.dawfinn.droiditarian;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dawfinn.droiditarian.server.data.DeedLocation;
import org.dawfinn.droiditarian.server.data.PMF;

@SuppressWarnings("serial")
public class DeedLocationInitServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Calendar c = new GregorianCalendar();

		List<Date> dates = new ArrayList<Date>();

		for (int i = 0; i < 5; i++) {
			c.add(Calendar.DAY_OF_MONTH, -i);
			dates.add(c.getTime());
		}

		try {
			Collection<DeedLocation> locs = new ArrayList<DeedLocation>();

//			for (int i = 0; i < 100; i++) {
//				locs.add(new DeedLocation(new GeoPt((float) 37.422006,
//						(float) -122.084095), "Give a microloan at Kiva.org",
//						dates.get(4)));
//				locs.add(new DeedLocation(new GeoPt((float) 35.27,
//						(float) -120.66), "Smile at someone", dates.get(1)));
//				locs
//						.add(new DeedLocation(new GeoPt((float) 36.77,
//								(float) -119.72),
//								"Remove a weed from your neighbor's lawn",
//								dates.get(2)));
//				locs.add(new DeedLocation(new GeoPt((float) 37.62,
//						(float) -122.38), "Walk an old lady across the street",
//						dates.get(3)));
//				locs.add(new DeedLocation(new GeoPt((float) 35.12,
//						(float) -120.59), "Tell a friend that you like them",
//						dates.get(0)));
//			}
			
			pm.makePersistentAll(locs);
		} finally {
			pm.close();
		}
	}
}
